// components/share.js

import url from "../../util/url.js"

Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  lifetimes: {
    attached: function () {
      this.updateUserInfo()
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    records:[],
    sumOfMoney:'00.00',
    userId:'',
    transfePoints:'0',
    money1:'0.00',
    money2:'0.00'
  },

  /**
   * 组件的方法列表
   */
  methods: {
    updateUserInfo: function () {
      wx.getStorage({
        key: 'userId',
        success: (res) => {
          let userId = res.data
          this.setData({
            userId: userId
          })
          if (userId){
          
            wx.request(
              {
                url: 'https://www.miaodaochina.com/share/records/reward',
                success: (res) => {
                  if (res.data && res.data && res.data.length > 0) {
                    this.setData({
                      money1: res.data[0].amount || '0.00', 
                    })
                  }
                },
                data: { userId: userId, status:0 },
              }
            )

            wx.request(
              {
                url: 'https://www.miaodaochina.com/share/records/reward',
                success: (res) => {
                  if (res.data && res.data && res.data.length > 2) {
                    this.setData({
                      money1: res.data[1].amount || '0.00',
                    })
                  }
                },
                data: { userId: userId, status: 1 },
              }
            )

            wx.request(
              {
                url: 'http://58.82.248.252:9090/notice/tPointsTransfer/query',
                success: (res) => {
                  if (res.data && res.data) {
                    this.setData({
                      transfePoints: transfePoints.transfePoints || 0
                    })
                  }
                },
                data: { userId: userId},
              }
            )

            wx.request(
              {
                url: url.shareRecord,
                success: (res) => {
                  if (res.data && Array.isArray(res.data)){
                    this.setData(
                      { records: res.data }
                    )
                  }
              
                },
                data: { userId: userId },
              }
            )

            wx.request(
              {
                url: url.teamCount,
                success: (res) => {
                  
                },
                data: { userId: userId },
              }
            )

            wx.request(
              {
                url: url.orderList,
                success: (res) => {

                },
                data: { 
                  userId: userId,
                  merchantNo: userId,
                  beginTime:'2018-01-01',  
                  endTime: '2021-01-01',
                  pageIndex:0,
                  pageSize:20,
                },
              }
            )
          }
        }
      })
     
    },
  }
})
